#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# author: leeyi <leeyisoft@icloud.com>
# Created on 2018-10-06 23:16:26

import os
import time
import logging

from pyspider.result import ResultWorker
from pyspider.database import connect_database
from src.utils import md5
from src.utils import to_timestamp


logger = logging.getLogger("ResultWorker")
# mysqldb = connect_database

class ResultWorker(ResultWorker):
    def on_result(self, task, result):
        """override"""
        # assert task['taskid']
        # assert task['project']
        # assert task['url']
        # assert result
        #
        # # self.resultdb
        # self.resultdb = resultdb
        # self.inqueue = inqueue
        '''Called every result'''
        if not result:
            return
        arc_url = result.get('url', '')
        if not arc_url:
            return
        mongo_config = os.environ.get('mongo_config', '')
        if not mongo_config:
            pass
        arc_md5 = md5(arc_url)
        logger.info(dir(self.resultdb))
        logger.info(dir(self.inqueue))
        logger.info(dir(self))
        logger.info(dir(task))
        logger.info(task)
        logger.info(result)

